package cn.edu.scau.cmi.huangxiaodong.client;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

import java.util.Vector;

import cn.edu.scau.cmi.huangxiaodong.singleton.*;
public class SingletonClient extends Application{
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub		
		HBox hb = new HBox();
		Label label1= new Label("单例模式");
		Label label0= new Label("请输入主席名:");
		label0.setFont(new Font("Arial", 20));
		TextField textField = new TextField ();
		Button bt=new Button("创建");
		hb.setSpacing(10);
		hb.getChildren().addAll( label0,textField,bt);
		label1.setFont(new Font("Arial", 28));
		VBox vbox0=new VBox();
		vbox0.setSpacing(10);
		vbox0.getChildren().addAll(label1,hb);	
		
		
		
		HBox hb1 = new HBox();
		Label label2= new Label("多例模式");
		label2.setFont(new Font("Arial", 30));
		Label label3= new Label("请输入元帅名:");
		label3.setFont(new Font("Arial", 20));
		TextField textField1 = new TextField ();
		Button bt1=new Button("创建");
		hb1.getChildren().addAll( label3,textField1,bt1);
		VBox vbox1=new VBox();
		vbox1.setSpacing(10);
		vbox1.getChildren().addAll(label2,hb1);
		
		HBox pane=new HBox();
		pane.setSpacing(150);
		pane.getChildren().addAll(vbox0,vbox1);
		Scene scene=new Scene(pane,1200,800);
		primaryStage.setTitle("第二次实验");
		primaryStage.setScene(scene);
		primaryStage.show();
	
	
		bt.setOnAction(event -> {
			Chairman chairman;
			String name=textField.getText().trim();
		if(!name.equals("")) {
			chairman=Chairman.getInstance(name);
			String name1=chairman.getName();
			if(!name.equals(name1)) {
				vbox0.getChildren().add(new Label("对象已经创建，现在你获得的对象是:"));
			}
			vbox0.getChildren().add(new Label(name1+chairman));			
		}else {
			vbox0.getChildren().add(new Label("名字不能为空"));
			}
		});
		
		bt1.setOnAction(event -> {
			Marshal  marshal ;
			String name=textField1.getText().trim();
		if(!name.equals("")) {
			
			if(Marshal.getNum()<10) {
				Vector vector=Marshal.getNamset();
				if(vector.indexOf(name)==-1) {
					marshal =Marshal .getInstance(name);
					String name1=marshal .getName();
					vbox1.getChildren().add(new Label(name1+marshal ));			
				}else {
					vbox1.getChildren().add(new Label(name+"元帅已创建"));			
				}				
			}
			else {
				vbox1.getChildren().add(new Label("已创建10个元帅,不能再创建了"));	
			}
			
		}else {
			vbox1.getChildren().add(new Label("名字不能为空"));
			}
			
});

}
 

}

